//
//  lxTitlePageControlView.m
//  luodansc
//
//  Created by 倫 星 on 2012/10/26.
//  Copyright (c) 2012年 方正株式会社. All rights reserved.
//

#import "lxTitlePageControlView.h"

@implementation lxTitlePageControlView

@synthesize lb_title = _lb_title;
@synthesize pageControl = _pageControl;

@synthesize lb_price = _lb_price;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        float gride_width = frame.size.width / 4;
        float front_width = gride_width / 10;
        CGRect ret_lb_t = CGRectMake(front_width, 0, gride_width - front_width, frame.size.height);
        _lb_title = [[lxLabel alloc] initWithFrame:ret_lb_t];
        _lb_title.adjustsFontSizeToFitWidth = YES;
        _lb_title.textColor = [UIColor cyanColor];
        _lb_title.textAlignment = NSTextAlignmentCenter;
        _lb_title.backgroundColor = [UIColor clearColor];
        _lb_title.text = @"";
        _lb_title.lineBreakMode = NSLineBreakByWordWrapping; 
        
        CGRect ret_pc = CGRectMake(gride_width, 0, gride_width * 2, frame.size.height);
        _pageControl = [[UIPageControl alloc] initWithFrame:ret_pc];
        _pageControl.currentPage = 0;
        _pageControl.hidesForSinglePage = YES;
        _pageControl.backgroundColor = [UIColor clearColor];
        
        CGRect ret_lb_p = CGRectMake(gride_width * 3, 0, gride_width - front_width, frame.size.height);
        _lb_price = [[lxLabel alloc] initWithFrame:ret_lb_p];
        _lb_price.adjustsFontSizeToFitWidth = YES;
        _lb_price.textColor = [UIColor redColor];
        _lb_price.textAlignment = NSTextAlignmentRight;
        _lb_price.backgroundColor = [UIColor clearColor];
        
        NSString *money = NSLocalizedString(@"money", nil);
        NSString *str_price = @"0";
        _lb_price.text = [NSString stringWithFormat:@"%@%@", str_price, money];
        
        self.backgroundColor = [UIColor blackColor];
        
        self.alpha = 0.4f;
        [self addSubview:_lb_title];
        [self addSubview:_pageControl];
        [self addSubview:_lb_price];
    }
    return self;
}

- (void)setTitleAndPrice:(NSString *)title price:(float)price {
    _lb_title.text = title;

    NSString *money = NSLocalizedString(@"money", nil);
    NSString *str_price = [lxStringUtility stringTrim:[NSString stringWithFormat:@"%10.2f", price]];
    if (YES == [lxStringUtility isNil:str_price]) {
        str_price = @"0";
    }
    _lb_price.text = [NSString stringWithFormat:@"%@%@", str_price, money];
}

- (void)dealloc {
    [_lb_title release];
    [_pageControl release];
    [_lb_price release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
